package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ErrorCode;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.DamageList;
import com.atguigu.jxc.entity.DamageListGoods;
import com.atguigu.jxc.entity.Goods;
import com.atguigu.jxc.service.DamageListGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("damageListGoods")
public class DamageListGoodsController {
    @Autowired
    private DamageListGoodsService damageListGoodsService;

    /**
     * 报损商品保存单
     * @return
     */
    @PostMapping("save")
    public ServiceVO save(DamageList damageList, String damageListGoodsStr, HttpServletRequest request){
        String damageNumber = request.getParameter("damageNumber");
        Boolean flag = damageListGoodsService.save(damageList,damageListGoodsStr,damageNumber);
        if (flag){
            return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
        }
        return new ServiceVO(ErrorCode.PARA_TYPE_ERROR_CODE,ErrorCode.REQ_ERROR_MESS);
    }

    /**
     * 查询商品报损单列表
     * @param sTime
     * @param eTime
     * @return
     */
    @PostMapping("list")
    public Map<String,Object> list(String  sTime, String  eTime){
        List<DamageList> list = damageListGoodsService.selectList(sTime,eTime);
        HashMap<String, Object> map = new HashMap<>();
        map.put("rows",list);
        return map;
    }

    /**
     * 查询报损单下边的商品
     * @param damageListId
     * @return
     */
    @PostMapping("goodsList")
    public Map<String,Object> goodsList(Integer damageListId){
        HashMap<String, Object> map = new HashMap<>();
        List<DamageListGoods> list = damageListGoodsService.getGoodslistFordamageListById(damageListId);
        map.put("rows",list);
        return map;
    }
}
